local chizheng = fk.CreateSkill {
    name = "SP_heg__chizheng",
    tags = { Skill.MainPlace, Skill.Limited },
}

Fk:loadTranslationTable {
    ["SP_heg__chizheng"] = "敕政",
    [":SP_heg__chizheng"] = "主将技，限定技，此武将牌上的单独阴阳鱼个数-1。出牌阶段，你可发起<a href='heg_Command'>“军令”</a>，然后令所有与你势力相同的角色选择一项：1.执行此军令，将手牌摸至其的体力值；" ..
    "2.受到你造成的1点伤害并摸两张牌。若你为大势力角色，你结束此回合。",

    ["#SP_heg__chizheng-active"] = "敕政：你可发起军令，然后然后令所有与你势力相同的角色选择执行此军令并将手牌摸至其的体力值<br>或受到你造成的1点伤害并摸两张牌",

    ["$SP_heg__chizheng1"] = "哼，同为托孤之臣，诸葛氏欺我太甚。",
    ["$SP_heg__chizheng2"] = "看我误了你的大事。",
}

local H = require "packages.ol_hegemony.util"

chizheng:addEffect("active", {
    anim_type = "offensive",
    prompt = "#SP_heg__chizheng-active",
    can_use = function(self, player)
        return player:usedSkillTimes(chizheng.name, Player.HistoryGame) == 0
    end,
    card_num = 0,
    target_num = 0,
    on_use = function(self, room, effect)
        local player = effect.from
        local index = H.startCommand(player, chizheng.name)
        local targets = table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) end)
        if #targets > 0 then
            room:doIndicate(player, targets)
            room:sortByAction(targets)
            for _, p in ipairs(targets) do
                if player.dead then break end
                if not p.dead and H.doCommand(p, chizheng.name, index, player) then
                    local num = math.min(p.hp, 5) - p:getHandcardNum()
                    if num > 0 then
                        p:drawCards(num, chizheng.name)
                    end
                else
                    room:damage({
                        from = player,
                        to = p,
                        damage = 1,
                        skillName = chizheng.name,
                    })
                    p:drawCards(2, chizheng.name)
                end
            end
        end
        if H.isBigKingdomPlayer(player) then
            room:endTurn()
        end
    end,
})

return chizheng
